<?
if (!defined('SMF'))
	die('Hacking attempt...');
	
global $colonist_reproduction_rate, $colonist_limit, $colonist_production_rate;
global $organics_prate, $organics_consumption;
global $ore_prate, $goods_prate, $energy_prate;
global $starvation_death_rate;
global $interest_rate, $credits_prate;
global $fighter_prate, $torpedo_prate;

$expoprod = mypw($colonist_reproduction_rate + 1, $multiplier);
$expoprod *= $multiplier;

$expocreds = mypw($interest_rate, $multiplier);

$message .= '<p><strong>PLANETS</strong></p>';

$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_planets}
	SET organics	=	organics + GREATEST(((LEAST(colonists, {int:colonist_limit}) * {float:colonist_production_rate}) 
						* {float:organics_prate} * prod_organics / 100.0 * {float:expoprod}) - LEAST(colonists, {int:colonist_limit}) 
						* {float:colonist_production_rate} * {float:organics_consumption} * {float:expoprod},0),
		ore			= 	ore + (LEAST(colonists,  {int:colonist_limit}) * {float:colonist_production_rate}) * {float:ore_prate}
						* prod_ore / 100.0 * {float:expoprod},
		goods		= 	goods + (LEAST(colonists, {int:colonist_limit}) * {float:colonist_production_rate}) * {float:goods_prate} 
						* prod_goods / 100.0 * {float:expoprod},
		energy		= 	energy + (LEAST(colonists, {int:colonist_limit}) * {float:colonist_production_rate}) * {float:energy_prate}
						* prod_energy / 100.0 * {float:expoprod},
		colonists	= 	LEAST(colonists + (colonists - (colonists * {float:starvation_death_rate})) * {float:colonist_reproduction_rate} 
						* {float:expoprod}, {int:colonist_limit}),
		credits		= 	credits * {float:expocreds} + (LEAST(colonists, {int:colonist_limit}) * {float:colonist_reproduction_rate}) * {float:credits_prate} 
						* (100.0 - prod_organics - prod_ore - prod_goods - prod_energy - prod_fighters - prod_torp) / 100.0 
						* {float:expoprod}',
	array(
		'db_planets' => $dbtables['planets'],
		'colonist_limit' => $colonist_limit,
		'colonist_production_rate' => $colonist_production_rate,
		'organics_prate' => $organics_prate,
		'expoprod' => $expoprod,
		'organics_consumption' => $organics_consumption,
		'ore_prate' => $ore_prate,
		'goods_prate' => $goods_prate,
		'energy_prate' => $energy_prate,
		'starvation_death_rate' => $starvation_death_rate,
		'colonist_reproduction_rate' => $colonist_reproduction_rate,
		'expocreds' => $expocreds,
		'credits_prate' => $credits_prate
	)
);

$update = $smcFunc['db_query']('', '
	UPDATE {raw:db_planets}
	SET fighters	=	fighters + (LEAST(colonists, {int:colonist_limit}) * {float:colonist_production_rate}) * {float:fighter_prate} 
						* prod_fighters / 100.0 * {float:expoprod},
    torps			=	torps + (LEAST(colonists, {int:colonist_limit}) * {float:colonist_production_rate}) * {float:torpedo_prate} 
						* prod_torp / 100.0 * {float:expoprod} 
    WHERE owner != 0',
	array(
		'db_planets' => $dbtables['planets'],
		'colonist_limit' => $colonist_limit,
		'colonist_production_rate' => $colonist_production_rate,
		'expoprod' => $expoprod,
		'fighter_prate' => $fighter_prate,
		'torpedo_prate' => $torpedo_prate
	)
);

$message .= 'Planets updated.<br><br>';

?>

